package com.nav.backend.service.impl;

import com.nav.backend.mapper.NavigateMapper;
import com.nav.backend.pojo.CollectionPath;
import com.nav.backend.pojo.RingSearch;
import com.nav.backend.pojo.TwoPointsSearch;
import com.nav.backend.service.NavigateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * NavigateServiceImpl 类实现了 NavigateService 接口，提供了导航相关的业务逻辑操作
 *
 * @author Seamher
 */
@Service
public class NavigateServiceImpl implements NavigateService {

    @Autowired
    private NavigateMapper navigateMapper;

    private static final Logger logger = LoggerFactory.getLogger(NavigateServiceImpl.class);

    /**
     * 添加导航历史记录
     *
     * @param searchOrigin      搜索起点
     * @param searchOriginX     搜索起点的 X 坐标
     * @param searchOriginY     搜索起点的 Y 坐标
     * @param searchDestination 搜索终点
     * @param searchDestinationX 搜索终点的 X 坐标
     * @param searchDestinationY 搜索终点的 Y 坐标
     * @param account           用户账号
     */
    @Override
    public void addHistory(String searchOrigin, Double searchOriginX, Double searchOriginY, String searchDestination, Double searchDestinationX, Double searchDestinationY, String account) {
        logger.info("Adding navigation history for account: {}, origin: {} ({}, {}), destination: {} ({}, {})",
                account, searchOrigin, searchOriginX, searchOriginY, searchDestination, searchDestinationX, searchDestinationY);
        navigateMapper.addHistory(searchOrigin, searchOriginX, searchOriginY, searchDestination, searchDestinationX, searchDestinationY, account);
    }

    /**
     * 添加环形导航历史记录
     *
     * @param searchLocation  搜索位置
     * @param searchLocationX 搜索位置的 X 坐标
     * @param searchLocationY 搜索位置的 Y 坐标
     * @param targetDistance  目标距离
     * @param account         用户账号
     */
    @Override
    public void addRingHistory(String searchLocation, Double searchLocationX, Double searchLocationY, Integer targetDistance, String account) {
        logger.info("Adding ring navigation history for account: {}, location: {} ({}, {}), target distance: {}",
                account, searchLocation, searchLocationX, searchLocationY, targetDistance);
        navigateMapper.addRingHistory(searchLocation, searchLocationX, searchLocationY, targetDistance, account);
    }

    @Override
    public TwoPointsSearch searchBySearchOrigin(String searchOrigin, String searchDestination) {
        return navigateMapper.searchBySearchOrigin(searchOrigin, searchDestination);
    }

    @Override
    public RingSearch searchBySearchLocation(String searchLocation) {
        return navigateMapper.searchBySearchLocation(searchLocation);
    }

    @Override
    public List<CollectionPath> mark(Double searchOriginX, Double searchOriginY, Double searchDestinationX, Double searchDestinationY, Double range) {
        return navigateMapper.mark(searchOriginX, searchOriginY, searchDestinationX, searchDestinationY, range);
    }
}
